package org.flowcircuit.model.component


import appearance.{Style, DrawContext, Appearance}
import coordinates.Pos

/**
 * A component, with some shape and appearance.
 * Has pins that can be connected to sockets on a Board.
 * 
 * @author Hans Haggstrom
 */
case class Component( pins : List[Pin], pinStyle : Style, appearance : Appearance, height : Float ) extends CircuitElement {

  def render( context : DrawContext ) {

    // render component pins (from location in component space to socket they are connected to)
    pins foreach { (pin : Pin) =>
      if (pin.socket != null) {
        context.spline( posDir.project( pin.posDir ), pin.socket.pos, pinStyle )
      }
      else {
        // TODO: Render some kind of handle that can be used to place a pin in a socket
      }
    }

    // Render component itself
    appearance.render( context.project( posDir ) )
  }


  def isInside(queryPos: Pos, context: DrawContext) : Boolean =
    appearance.isInside( queryPos, context.project( posDir ) )

}

